package br.edu.utfpr.sgbd;

import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.hibernate.tool.hbm2ddl.SchemaUpdate;
public class GeraBanco
{
	public static void main(String[] args)
	{
		Configuration configuration = new HibernateConfiguration().getConfiguration();
		configuration.configure();
		
		boolean atualizar = false;
		if(atualizar)
		{
			SchemaUpdate su = new SchemaUpdate(configuration);
			su.execute(true, true);
		}
		else
		{
			SchemaExport se = new SchemaExport(configuration);
			se.create(true, true);
			try
			{
				criaConfiguracaoDefault();
			}
			catch(Exception e)
			{
				e.printStackTrace();
			} // só cria o admin quando cria o banco
		}
	}
	
	private static void criaConfiguracaoDefault() throws Exception
	{
		HibernateUtil.getInstance().currentSession();
		HibernateUtil.getInstance().beginTransaction();
				
		HibernateUtil.getInstance().commitTransaction();
		System.exit(0);
	}
}
